#!/bin/zsh -f

# The theme will put square brackets around the venv string unless
# these values are non-null (according to the zsh docs). Ironically,
# the null byte is not considered to be null for ${name:=word}
ZSH_THEME_VIRTUALENV_PREFIX=" %F{033}❮%f \xF0\x9F\x90\x8D "
ZSH_THEME_VIRTUALENV_SUFFIX="%f\0"
ZSH_THEME_GIT_PROMPT_PREFIX=" %F{033}❮%f %F{yellow}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%K{235} %k"
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{red}%B✗%b%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %F{green}%B✔%b%{$reset_color%}"
arrow="%F{245}❯%f"

function theme_precmd {
  local cwd="$(pwd)"
  cwd_string="$(pwd)"

  if [[ "$cwd_string" == *"$HOME"* ]]; then
    cwd_string="${cwd_string/$HOME/~}"
  else
    cwd_string="${cwd_string#/*}"
  fi

  if [[ "$cwd_string" != "~" ]]; then
    cwd_string="%F{250}${${cwd_string%/*}//\// ${arrow} } ${arrow} %F{255}${cwd_string##*/}"
    if [[ "$cwd_string" != "%F{250}~"* ]]; then
      cwd_string="/ ${arrow} ${cwd_string//\// ${arrow} }"
    fi
  fi
}

PROMPT=$'\e[?7l%K{235}%m ${arrow} ${cwd_string}%f$(virtualenv_prompt_info)$(git_prompt_info)%K{235}\e[?7h%k\n%#%f%k '
RPROMPT=""
PS2='%F{084}%_%f > '

autoload -U add-zsh-hook
add-zsh-hook precmd theme_precmd
